package com.esdk.sql;

import com.esdk.esdk;


public class WrapSelect extends Select{
  public WrapSelect(ISelect select,String alias){
		this(select);
		this.getTable().setAliasName(alias);
  }

	/* 该构造方法一般用于JoinSelect JoinSelect能够自动生成别名 */
	public WrapSelect(ISelect select){
		this.setTableName("("+select.getSQL().replaceAll("\\r?\\n"," ")+")");
		this.setTop(0);
		this.setConnection(select.getConnection());
	}

	public static void main(String[] args){
		Select s=new Select("dict");
		s.addEqualCondition("valid",true);
		s.setColumns("category","name","content","sequence");
		WrapSelect ns=new WrapSelect(s,"d1");
		ns.setColumns("category,name");
		ns.addOrderBy("name");
		esdk.tool.assertEquals(ns.getSQL(),"Select d1.category,d1.name\r\n" +
				"From (Select category,name,content,sequence From dict Where valid = 1 Limit 50) d1\r\n" +
				"Order By d1.name");
	}
}
